﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UdrinkWater_Project.Officer
{
    public partial class ShowDataEmp : System.Web.UI.Page
    {
        string Connection = ConfigurationManager.ConnectionStrings["DB_Udrink"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
           DataTable dt = new DataTable();
            dt = GetData_Emp();
            ASPxFormLayout1_E1.Text = dt.Rows[0]["ID_Card"].ToString();
            ASPxFormLayout1_E2.Text = dt.Rows[0]["Prefix"].ToString();
            ASPxFormLayout1_E3.Text = dt.Rows[0]["Firstname"].ToString();
            ASPxFormLayout1_E4.Text = dt.Rows[0]["Lastname"].ToString();
            ASPxFormLayout1_E5.Text = dt.Rows[0]["Department_Name"].ToString();
            ASPxFormLayout1_E6.Text = dt.Rows[0]["Salary"].ToString();
            ASPxFormLayout1_E7.Text = Convert.ToDateTime(dt.Rows[0]["StartJob"]).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("th-TH"));
            ASPxFormLayout1_E8.Text = dt.Rows[0]["Address"].ToString();
            ASPxFormLayout1_E9.Text = dt.Rows[0]["DISTRICT_NAME"].ToString();
            ASPxFormLayout1_E10.Text = dt.Rows[0]["AMPHUR_NAME"].ToString();
            ASPxFormLayout1_E11.Text = dt.Rows[0]["PROVINCE_NAME"].ToString();
            ASPxFormLayout1_E12.Text = dt.Rows[0]["Tel"].ToString();

        }
        public DataTable GetData_Emp()
        {
            DataTable dt = new DataTable();
            string sqltext = @"SELECT TB_Employee.ID_Card, TB_Employee.Prefix, TB_Employee.Firstname, TB_Employee.Lastname, TB_Employee.Address,
                               TB_Employee.Tel, TB_Employee.Salary, TB_Employee.StartJob, TB_Aumphur.AMPHUR_NAME, TB_District.DISTRICT_NAME, 
                               TB_Province.PROVINCE_NAME, TB_Department.Department_Name FROM TB_Employee INNER JOIN TB_Department 
                               ON TB_Employee.Department_ID = TB_Department.Department_ID INNER JOIN TB_Province 
                               ON TB_Employee.PROVINCE_ID = TB_Province.PROVINCE_ID INNER JOIN TB_Aumphur ON TB_Employee.AMPHUR_ID = TB_Aumphur.AMPHUR_ID 
                               INNER JOIN TB_District ON TB_Employee.DISTRICT_ID = TB_District.DISTRICT_ID WHERE TB_Employee.ID_Card='" + Session["User"].ToString() + "' ";
            SqlConnection sqlconn = new SqlConnection(Connection);
            SqlDataAdapter da = new SqlDataAdapter(sqltext, sqlconn);
            DataSet ds = new DataSet();
            da.Fill(ds);

            return ds.Tables[0];
        }
    }
}